#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright [Gtlions Lai].
# Create Date:
# Update Date:
"""summarization ahout this script.

detail ahout this script

   Class(): summarization about Class
   ...
   function(): summarization about function
   ...
"""
__authors__ = '"Gtlions Lai" <gtlions.l@qq.com>'

import sys
from PyQt4 import QtGui, QtCore


class Main(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self)
        self.setWindowTitle('QWidget')
        self.setGeometry(300, 300, 300, 300)
        grid = QtGui.QGridLayout()
        self.setLayout(grid)

        self.bt1 = QtGui.QPushButton('show time')
        grid.addWidget(self.bt1, 0, 0)
        self.bt2 = QtGui.QPushButton('show others')
        grid.addWidget(self.bt2, 0, 1)
        self.qe1 = QtGui.QTextBrowser()
        grid.addWidget(self.qe1, 1, 0, 1, 2)

        QtCore.QObject.connect(self.bt1, QtCore.SIGNAL('clicked()'), self.showtime)

    def update_execret(self, message):
        self.qe1.insertPlainText(message)

    def showtime(self):
        currenttime = QtCore.QTime.toString(QtCore.QTime.currentTime(), 'h:m:s ap')
        self.qe1.append('show time: ' + currenttime + '\n')
        thread = Worker(self)  # 创建线程
        thread.trigger.connect(self.update_execret)
        thread.setup('asdf')  # 传递参数
        thread.start()  # 启动线程


class Worker(QtCore.QThread):
    trigger = QtCore.pyqtSignal(str)

    def __init__(self, parent=None):
        super(Worker, self).__init__(parent)

    def setup(self, args):
        self.args = args


    def run(self):
        print self.args
        self.trigger.emit(u' 一共有[' + self.args + u']张表. \n')



if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main = Main()
    main.show()
    sys.exit(app.exec_())